<% layout('/layouts/default.html', {title: '考核任务指标表管理', libs: ['layout','dataGrid','ueditor','inputmask']}){ %>
<style>

</style>
<div class="main-content">
    <div class="box box-main">
        <div class="box-body" style="display: none">
            <#form:form id="searchForm" model="${dcSupExamQuotaInfo!}"
            action="${ctx}/quota/dcSupExamSumQuotaInfo/quotaPageList?exameOrg=${dcSupExamSumQuotaInfo.exameOrg}&versionNumber=${dcSupExamSumQuotaInfo.versionNumber}&examId=${dcSupExamSumQuotaInfo.examId}&examYear=${dcSupExamSumQuotaInfo.examYear}"
            method="post" class="form-inline "
            data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize!5}"
            data-order-by="${parameter.orderBy}">
        </#form:form>
    </div>
    <div class="box-header" style="display: flex;justify-content: right;">
        <div id="danxiang" style="padding-bottom: 8px"><span style ="font-size: 18px;color: #30bbbb">当前版本:${dcSupExamSumQuotaInfo.versionName}</span></div>
    </div>
    <div class="box-body">
        <table id="dataGrid"></table>
        <div id="dataGridPage"></div>
    </div>

    <div class=" box-body">
        <div class="ui-layout-content">
            <#form:form id="searchForm2" model="${dcSupExamQuotaInfo!}"
            action="${ctx}/quota/dcSupExamSumQuotaInfo/listOrgByQuota" method="post" class="form-inline hide"
            data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize!20}"
            data-order-by="${parameter.orderBy}">
            <#form:hidden path="exameOrg" id="exameOrg"/>
            <#form:hidden path="versionNumber" id="versionNumber"/>
            <#form:hidden path="examId" id="examId"/>
            <#form:hidden path="examYear" id="examYear"/>
            <#form:hidden path="exameOrgName" id="exameOrgName"/>
            <div class="form-group">
                <label class="control-label">${text('指标')}：</label>
                <div class="control-inline width-90">
                    <#form:input name="quotaContent" id="quotaContent" class="form-control"/>
                </div>
            </div>
        </#form:form>
        <form id="inputForm2">
            <table id="dataGrid2"></table>
            <div id="dataGrid2Page"></div>
        </form>
    </div>


</div>
<% } %>
<style>
    .SelectBG td{
        background: #eaeaea !important;
        background-color: #eaeaea !important;
        color:blue;
    }
</style>
<script>
    var exameOrg = '${dcSupExamSumQuotaInfo.exameOrg}';
    var versionNumber = '${dcSupExamSumQuotaInfo.versionNumber}';
    var examId = '${dcSupExamSumQuotaInfo.examId}';
    var examYear = '${dcSupExamSumQuotaInfo.examYear}';
    var exameOrgName = '${dcSupExamSumQuotaInfo.exameOrgName}';
    $('#dataGrid2').dataGrid({
        searchForm: $("#searchForm2"),
        dataGridPage: $('#dataGrid2Page'),
        autoGridHeight: function () {
            return 210;
        },
        columnModel: [
            {header: '${text("序号")}', name: 'sortNum', width: 100, align: "center",
                editable: true, edittype: 'text', editoptions: {
                    'maxlength': '200', 'class': 'form-control',
                    'placeholder':'数字排序'
                },
                unformat: function (val, obj, cell) {
                    return $('#' + obj.rowId + '_sortNum').val();
                }},
            {header: '${text("排序")}', name: 'quotaInfoId', hidden: true},
            {header: '${text("排序")}', name: 'id', hidden: true},
            {header: '${text("被考核单位")}', name: 'exameOrg', hidden: true},
            {header: '${text("quotaId")}', name: 'quotaId', hidden: true},
            {header: '${text("被考核单位名称")}', name: 'exameOrgName', width: 150, align: "left"},
            {header: '${text("类型")}', name: 'orgType', width: 150, align: "center",
                formatter: function (val, obj, row, act) {
                    if (val == '1') {
                       return "区县";
                    }else if (val == '2'){
                        return "市直"
                    }else{
                        return ""
                    }
                }
            },
            {
                header: '${text("单位")}', name: 'quotaUnit', index: 'a.quota_unit', width: 100, align: "center",
                editable: true, edittype: 'text', editoptions: {
                    'maxlength': '200', 'class': 'form-control',
                    'placeholder': '例:亿元、万元、个、条、家、项、户等;若无则不填'
                },
                unformat: function (val, obj, cell) {
                    return $('#' + obj.rowId + '_quotaUnit').val();
                }
            },
            {
                header: '${text("权数")}', name: 'quotaWeight', index: 'a.quota_weight', width: 60, align: "center",
                editable: true, edittype: 'text', editoptions: {
                    'maxlength': '200', 'class': 'form-control required dx',
                    dataInit: function (element) {
                        var number = $('#' + element.id).val();
                        $(element).on("change", function () {
                            var val = $('#' + element.id).val();
                            var plus = $("#plus").val();
                            if (plus == '加分项') {
                                if (val > 3) {
                                    js.showMessage("加分项权数不能超过3！");
                                    $('#' + element.id).val(number);
                                }
                            }
                        });
                        $(element).on("keyup", function () {
                            $('#' + element.id).val($('#' + element.id).val().replace(/[^\d.]/g, ""));
                            $('#' + element.id).val($('#' + element.id).val().replace(/^\./g, ""));
                            $('#' + element.id).val($('#' + element.id).val().replace(/\.{2,}/g, "."))
                            $('#' + element.id).val($('#' + element.id).val().replace(".", "$#$").replace(/\./g, "").replace("$#$", "."))
                            $('#' + element.id).val($('#' + element.id).val().replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'));
                        })
                    }
                },
                unformat: function (val, obj, cell) {
                    return $('#' + obj.rowId + '_quotaWeight').val();
                },
                formatter: function (val, obj, row, act) {
                    if (val == null) {
                        val = 0;
                    }
                    var wg = parseFloat(val).toFixed(2);
                    return wg;
                }
            },
            {
                header: '${text("本年度目标")}',
                name: 'currentYaerGoal',
                index: 'a.current_yaer_goal',
                width: 150,
                align: "center",
                editable: true,
                edittype: 'text',
                editoptions: {'maxlength': '200', 'class': 'form-control required dx'},
                unformat: function (val, obj, cell) {
                    return $('#' + obj.rowId + '_currentYaerGoal').val();
                }
            },
            {
                header: '${text("考核方式")}',
                name: 'assessMethod',
                index: 'a.assessMethod',
                width: 100,
                align: "center",
                editable: true,
                edittype: 'text',
                editoptions: {'maxlength': '200', 'class': 'form-control required dx'},
                formatter: function (val, obj, row, act) {
                    return js.getDictLabel(${@DictUtils.getDictListJson('dc_exam_assessment')},
                        val, '${text("未知")}', true);
                },
                editable: true,
                edittype: 'select',
                editoptions: {
                    'class': 'form-control required dx',
                    items: $.merge([], ${@DictUtils.getDictListJson('dc_exam_assessment')}),
                    itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function (element) {
                        $(element).select2().on("change", function () {
                            $(this).resetValid()
                        });
                    }
                },
                unformat: function (val, obj, cell) {
                    return $('#' + obj.rowId + '_' + obj.colModel.name, cell).val();
                }
            },
            {
                header: '${text("备注")}', name: 'remarks', index: 'a.remarks', width: 50, align: "center",
                editable: true, edittype: 'text', editoptions: {'maxlength': '200', 'class': 'form-control'},
                formatter: function (val, obj, row, act) {
                    return js.getDictLabel(${@DictUtils.getDictListJson('dc_exam_remarks')},
                        val, '${text("未知")}', true);
                },
                editable: true, edittype: 'select', editoptions: {
                    'class': 'form-control required gj',
                    items: $.merge([], ${@DictUtils.getDictListJson('dc_exam_remarks')}),
                    itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function (element) {
                        $(element).select2().on("change", function () {
                            $(this).resetValid()
                        });
                    }
                },
                unformat: function (val, obj, cell) {
                    return $('#' + obj.rowId + '_' + obj.colModel.name, cell).val();
                }
            },
            {
                header: '${text("操作")}',
                name: 'actions',
                width: 250,
                align: "center",
                formatter: function (val, obj, row, act) {
                    var actions = [];
                    actions.push('<a href="#" onclick=xiugaiInfo("'+row.id+'")  class="btn btn-primary btn-xs xg" title="${text("修改")}" >修改</a>&nbsp;');
                    actions.push('<a href="#" onclick=updateInfo("'+row.id+'")  class="btn btn-primary btn-xs bc" style="display: none" title="${text("保存")}" >保存</a>&nbsp;');
                    actions.push('<a href="javascript:void(0);" onclick="del(\''+(row.id)+'\')"  class="btn btn-danger btn-xs" title="${text("删除考核指标")}">删除</a>&nbsp;');
                    return actions.join('');
                }
            }
        ],
        showRownum: false,
        // 加载成功后执行事件
        editGridInitRowNum: 0,
        emptyDataHint: true,
        editGrid: false,
        autoGridHeight: function () {
            return 800;
        },
        ajaxSuccess: function (data) {

        }

    })
    function xiugaiInfo(id){
        $('#dataGrid2').dataGrid('editRow', id, {keys:true, focusField:false});
        let xg= $("#"+id).find("a")[0];
        $(xg).css("display","none")
        let bc= $("#"+id).find("a")[1];
        $(bc).css("display","inline")
    }
    function updateInfo(id) {

        let data=$('#dataGrid2').dataGrid('getRowData',$('#dataGrid2').dataGrid('getSelectRow'));
        delete data["actions"]
        delete data["orgType"]
        let allData =JSON.stringify(data);
        let dcSupExamSumQuotaInfo ={"dcSupExamSumQuotaInfo":allData}
        let xg= $("#"+id).find("a")[0];
        $(xg).css("display","inline")
        let bc= $("#"+id).find("a")[1];
        $(bc).css("display","none")
        $('#dataGrid2').dataGrid('saveRow',id);

        js.ajaxSubmit({url:"${ctx}/quota/dcSupExamSumQuotaInfo/updateSumOrg",data:dcSupExamSumQuotaInfo,dataType: 'json',callback:function (data){
                if (data.result=="true"){
                    js.showMessage("修改成功");
                    $('#dataGrid2').dataGrid('reloadGrid');
                }else {
                    js.showMessage(data.message);
                    $('#dataGrid2').dataGrid('reloadGrid');
                }
            }})
    }
    // 初始化DataGrid对象
    $('#dataGrid').dataGrid({
        searchForm: $("#searchForm"),
        columnModel: [
            {
                header: '${text("指标类别")}', name: 'quotaType', width: 150, align: "center",
                formatter: function (val, obj, row, act) {
                    return js.getDictLabel(${@DictUtils.getDictListJson('dc_quotaType')},
                        val, '${text("未知")}', true);
                },
                unformat: function (val, obj, cell) {
                    return $('#' + obj.rowId + '_quotaType').val();
                },
                editable: true, edittype: 'select', editoptions: {
                    'class': 'form-control',
                    items: $.merge([{dictLabel: '&nbsp;', dictValue: ''}],
                        ${@DictUtils.getDictListJson('dc_quotaType')}),
                    itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function (element) {
                        $(element).select2().on("change", function () {
                            $(this).resetValid()
                        });
                    }
                }
            },
            {header: '${text("主键")}', name: 'id', hidden: true},
            {header: '${text("序号")}', name: 'sortNum', width: 80, align: "center", hidden: true},
            {header: '${text("目标内容")}', name: 'quotaContent', index: 'a.quota_content', width: 350, align: "left"},
            {
                header: '${text("操作")}',
                name: 'actions',
                width: 250,
                align: "center",
                formatter: function (val, obj, row, act) {
                    var actions = [];
                    actions.push('<a href="javascript:void(0);" id="'+row.quotaContent+'" onclick="saveVersion(\''+row.quotaContent+'\');" class="btn btn-primary btn-xs" title="${text("修改")}">修改</a>&nbsp;');
                    actions.push('<a href="javascript:void(0);" onclick="delSumInfo(\''+(row.quotaContent)+'\')"  class="btn btn-danger btn-xs" title="${text("删除考核指标")}">删除</a>&nbsp;');
                    return actions.join('');
                }
            },
        ],
        showRownum: false,
        emptyDataHint: true,
        autoGridHeight: function () {
            return 210;
        },
        onSelectRow: function (id, isSelect, event) {
            var data = $('#dataGrid').dataGrid('getRowData', id);
            $("#quotaContent").val(data.quotaContent);
            $("#examYear").val(examYear);
            $('#versionNumber').val(versionNumber);
            $("#examId").val(examId);
            $('#exameOrg').val(exameOrg);
            $('#dataGrid2').dataGrid('refresh');
        },
        ajaxSuccess: function (data) {
            if (data.count > 0){
                $('#dataGrid tr').eq(1).addClass('SelectBG')
                $('#dataGrid tr').click(function(){
                    $(this).siblings().removeClass('SelectBG');
                    $(this).addClass('SelectBG');
                })
               let info= data.list[0];
                $("#quotaContent").val(info.quotaContent);
                $("#examYear").val(examYear);
                $('#versionNumber').val(versionNumber);
                $("#examId").val(examId);
                $('#exameOrg').val(exameOrg);
                $('#dataGrid2').dataGrid('refresh');
            }
        }
    });


    function saveVersion(quotaContent){
        js.layer.open({
            type: 2,
            title: ["修改内容<i style='color: red;font-size: 12px;font-style: normal'>(*请在需修改的选项中填入内容,不填则不做修改)</i>"],
            area: ['1000px', '800px'],
            // groupId 随便传  isGroupOptions 非常用组功能使用传 0  type  1 为区县 2 为市直
            content: "${ctx}/quota/dcSupExamSumQuotaInfo/changeQuotaContent?versionNumber="+versionNumber+"&examId="+examId+"&examYear="+examYear+"&exameOrg="+exameOrg+"&quotaContent="+quotaContent+"&exameOrgName="+exameOrgName,
            success: function(layero, index){
            },end:function (){
                $("#examYear").val(examYear);
                $('#versionNumber').val(versionNumber);
                $("#examId").val(examId);
                $('#exameOrg').val(exameOrg);
                $('#dataGrid').dataGrid('refresh');
            }
        })

    }

    function del(id){
        js.layer.open({
            type: 1
            ,title: ['信息', 'font-size:15px; color:orange;font-weight:bold;']
            ,btn: ['确认', '取消']
            ,btnAlign: 'c'
            ,area: '300px;'
            ,moveType: 1 //拖拽模式，0或者1
            ,content: "<div style=\"padding: 50px\"><i class='layui-layer-ico layui-layer-ico3' style='width: 30px;height: 30px;'></i>确认要删除吗？(如果当前指标只有一个被考核单位，则该指标也会被删除)</div>"
            ,yes: function(layero){
                js.ajaxSubmit(
                    '${ctx}/quota/dcSupExamSumQuotaInfo/delete?id='+id,
                    function (data){
                        if (data.result == "true"){
                            js.showMessage("删除成功");
                            $('#dataGrid').dataGrid('refresh');
                        }else{
                            js.showMessage("删除失败")
                        }
                    });
            }
        });

    }

    function delSumInfo(quotaContent){
        js.layer.open({
            type: 1
            ,title: ['信息', 'font-size:15px; color:orange;font-weight:bold;']
            ,btn: ['确认', '取消']
            ,btnAlign: 'c'
            ,area: '300px;'
            ,moveType: 1 //拖拽模式，0或者1
            ,content: "<div style=\"padding: 50px\"><i class='layui-layer-ico layui-layer-ico3' style='width: 30px;height: 30px;'></i>确认要删除该指标吗？</div>"
            ,yes: function(layero){
                js.ajaxSubmit(
                    "${ctx}/quota/dcSupExamSumQuotaInfo/delSumInfo?versionNumber="+versionNumber+"&examId="+examId+"&examYear="+examYear+"&exameOrg="+exameOrg+"&quotaContent="+quotaContent+"&exameOrgName="+exameOrgName,
                    function (data){
                        if (data.result == "true"){
                            js.showMessage("删除成功");
                            $('#dataGrid').dataGrid('refresh');
                        }else{
                            js.showMessage("删除失败")
                        }
                    });
            }
        });

    }


</script>